//src/user/repositories/user.repo.ts
import { Injectable } from "@nestjs/common";
import { InjectRepository } from "@nestjs/typeorm";
import { Repository } from "typeorm";
import { User } from "../entities/user.entity";

@Injectable()
export class UserRepository {
    constructor(
        @InjectRepository(User)
        private readonly userRepo: Repository<User>
    ){}
    
    async upsertUser(userDate:Partial<User>):Promise<User>{
        const entity = await this.userRepo.create(userDate);
        return this.userRepo.save(entity);
    }
    
    async findUserById(id: string): Promise<User | null> {
     return this.userRepo.findOneBy({ id });
    }
}